package com.team.work.dao;

import com.team.work.entities.News;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface NewRepository extends JpaRepository<News,Long> , JpaSpecificationExecutor<News>{
        @Query("select n from News n where n.title like ?1 or n.content like ?1")
        Page<News> findByQuery(String query, Pageable pageable);   //自定义sql语句进行查询

        //凡是被推荐都会被找出来
        @Query("select n from News n where n.recommend = true ")
        List<News> findTop(Pageable pageable);

}
